package com.czbank.financing.controller;

import com.czbank.financing.Entity.UserInfo;
import com.czbank.financing.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * @Auther: thinkpad
 * @Date: 2019/7/11 10:17
 * @Description:
 */
@Controller
@RequestMapping("/financing")
public class LoginController {
    @Autowired
    private LoginService loginService;

/*    @RequestMapping("/login")
    public String login( Model model,
     UserInfo userInfo){
        boolean existCardNo=loginService.existAccount(userInfo.getAccount());
        System.out.println("userInfo.getAccount() = " + userInfo.getAccount());
        userInfo = loginService.Login(userInfo.getAccount(),userInfo.getPassword() );
        if (existCardNo){
            userInfo = loginService.Login(userInfo.getAccount(),userInfo.getPassword() );
            if (userInfo==null){
                model.addAttribute("errorMsg", "密码错误");
                return "user/login";
            }
            else {

                return "user/main";
            }
        }else {
            model.addAttribute("errorMsg", "卡号不存在");
            return "user/login";
        }

    }*/
/*    @RequestMapping("/login")
    public String login(@RequestParam("account") String account,
                        @RequestParam("password") String password,HttpSession session){
        UserInfo userInfo = loginService.Login(account,password);
        if (userInfo==null){
            return "user/main";
        }else {
            return "user/main2";
        }
    }*/

    @GetMapping("/login")
    public String logindata(Model model){
        model.addAttribute("userInfo", new UserInfo());
        return "user/Userlogin";

    }

    @PostMapping("/login")
    public String loginsun(@ModelAttribute UserInfo userInfo){
        userInfo = loginService.Login(userInfo.getAccount(),userInfo.getPassword());
        if (userInfo==null){
            return "user/main2";
        }else {
            return "user/main";
        }


    }
    @RequestMapping("/Index")
    public String ftlIndex() {

        return "user/index";
    }


}


